#!/usr/bin/env python
# -*- coding:utf-8 -*-

import redis

class RedisUtils(object):
    """
    说明：python3.7实现的对Redis的增删改查
    参考：
    https://www.cnblogs.com/progor/p/8567640.html
    http://www.cnblogs.com/progor/p/8540246.html
    """

    def __init__(self, host, port):
        """
        参数参考：
        class redis.StrictRedis(host=‘localhost‘, port=6379, db=0, password=None, socket_timeout=None, connection_pool=None, charset=‘utf-8‘, errors=‘strict‘, decode_responses=False, unix_socket_path=None)
        :param host:
        :param port:
        """
        # 连接池
        self.pool = redis.ConnectionPool(host=host, port=port, decode_responses=True)
        # 获取一个连接
        self.redis = redis.StrictRedis(connection_pool=self.pool)

    def get_by_key(self):
        pass

    def set_key_and_value(self, key, value):
        self.redis.set(key, value)
        pass

    def batch_set(self):
        pass

    def close(self):
        pass


if __name__ == '__main__':
    redis_utils = RedisUtils('172.18.22.215', '6379')
    redis_utils.redis.setex('zhangsa', 60, [1, 2, 3, 4, 5])